package com.googlecode.continuity.core.client.forms;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.googlecode.continuity.core.client.GWTExternal;

/**
 * InjectRichTextEditors, form controlling class that allows replacing simple text areas with rich text editors.
 *
 * todo: convert into UIEntryPoint
 * todo: read text box names from generic property
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class InjectRichTextEditors implements EntryPoint {
  /**
   * Replaces a set of text areas with rich text editors.  The names of the text editors are extracted from ...
   */
  public void onModuleLoad() {
    /*RootPanel root = GWTExternal.prepareEntryPoint("com.googlecode.continuity.core.client.InjectRichTextEditors");
    if (root == null) {
      return;
    }
    String[] names = getRichTextEditorNames().split(":");
    for (int i = 0; i < names.length; i++) {
      String name = names[i];
      Element original = DOM.getElementById(name);
      if (original == null) {
        continue;
      }
      TextArea box = new TextArea();
      DOM.setElementProperty(box.getElement(), "id", DOM.getElementProperty(original, "id"));
      DOM.setElementProperty(box.getElement(), "name", DOM.getElementProperty(original, "name"));
      box.setText(DOM.getInnerHTML(original));
      Element parent = DOM.getParent(original);
      DOM.removeChild(parent, original);
      DOM.appendChild(parent, box.getElement());
    }*/

  }

  private native String getRichTextEditorNames() /*-{
    return $wnd.GWTExternal.getRichTextEditorNames();
  }-*/;
}
